package com.zs.grain

import android.content.BroadcastReceiver
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.media.AudioManager
import android.widget.Toast
import com.jeremyliao.liveeventbus.LiveEventBus
import com.zs.grain.service.DataService

import com.zs.grain.service.SoundService
import javax.inject.Inject

class AlarmReceiver2: BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent?) {
        //val vol = intent?.getStringArrayExtra("time")
        var vol = intent!!.getIntExtra("volumn2", 0)
        var final = vol/6 - 1
        Toast.makeText(context,vol.toString(),Toast.LENGTH_SHORT).show();
        val am = context!!.getSystemService(Context.AUDIO_SERVICE) as AudioManager
       // var volumnCurrent = am.getStreamVolume(AudioManager.STREAM_MUSIC)
       // if(volumnCurrent<16) {
            am.setStreamVolume(
                AudioManager.STREAM_MUSIC,
                final,
                AudioManager.FLAG_PLAY_SOUND
            )
        LiveEventBus.get("vol2").post(vol)
    }
}